package com.example.gulimallproduct.web;

import com.example.gulimallproduct.entity.CategoryEntity;
import com.example.gulimallproduct.service.CategoryService;
import com.example.gulimallproduct.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        //TODO 查询所有的1级分类
        System.out.println("aaa");
        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Categries();
        model.addAttribute("categories",categoryEntityList);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/json/catalog.json")
    public Map<String, List<Catalog2Vo>> getCatalogJson(){
        System.out.println("aaa");
        Map<String, List<Catalog2Vo>> catelogJson = categoryService.getCatalogJson();
        return catelogJson;
    }
}
